package com.leetcodehot.problems;

public class problems2212 {
    private int[] res;
    private int[] temp;
    private int tempCount = 0;
    private int maxCount = 0;
    private int numArrows;

    public int[] maximumBobPoints(int numArrows, int[] aliceArrows) {
        res = new int[12];
        temp = new int[12];
        this.numArrows = numArrows;
        dfs(aliceArrows, 11);
        return res;
    }

    private void dfs(int[] aliceArrows, int i) {
        if (i == -1) {
            if (tempCount >= maxCount) {
                maxCount = tempCount;
                for (int j = 11; j >= 0; j--) {
                    res[j] = temp[j];
                    if (numArrows > 0 && j == 0) {
                        res[j] += numArrows;
                    }
                }
            }
            return;
        }

        // 不选
        dfs(aliceArrows, i - 1);

        // 选
        if (aliceArrows[i] < numArrows) {
            temp[i] = aliceArrows[i] + 1;
            numArrows -= aliceArrows[i] + 1;
            tempCount += i;
            dfs(aliceArrows, i - 1);
            temp[i] -= aliceArrows[i] + 1;
            numArrows += aliceArrows[i] + 1;
            tempCount -= i;
        }
    }
}
